package com.blog.cmrpersonalblog.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 用户点赞实体类
 */
@Data
@TableName("user_like")
public class UserLike {

    /**
     * 点赞ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 用户ID
     */
    @TableField("user_id")
    private Long userId;

    /**
     * 目标ID（文章ID或评论ID）
     */
    @TableField("target_id")
    private Long targetId;

    /**
     * 目标类型 1-文章 2-评论
     */
    @TableField("target_type")
    private Integer targetType;

    /**
     * 状态 0-取消点赞 1-点赞
     */
    @TableField("status")
    private Integer status;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /**
     * 目标类型常量
     */
    public static final int TARGET_TYPE_ARTICLE = 1;
    public static final int TARGET_TYPE_COMMENT = 2;

    /**
     * 状态常量
     */
    public static final int STATUS_UNLIKE = 0;
    public static final int STATUS_LIKE = 1;

    /**
     * 是否点赞状态
     */
    public boolean isLiked() {
        return status != null && status == STATUS_LIKE;
    }

    /**
     * 是否取消点赞状态
     */
    public boolean isUnliked() {
        return status != null && status == STATUS_UNLIKE;
    }
}
